﻿using System.Collections.Generic;
using System.Web;
using JQuery.WebKit.Common.Utilities;

namespace JQuery.WebKit.WebCommon.Templates
{
    public static class Template
    {
        public static string Load(string templatePath)
        {
            string fileName = HttpContext.Current.Server.MapPath(templatePath);
            string content = CachedFile.GetFileContent(fileName);
            if (string.IsNullOrEmpty(content))
            {
                return string.Empty;
            }
            return content;
        }

        public static string Fill(string templatePath, Dictionary<string, string> values)
        {
            string fileName = HttpContext.Current.Server.MapPath(templatePath);
            string content = CachedFile.GetFileContent(fileName);
            if (string.IsNullOrEmpty(content))
            {
                return string.Empty;
            }
            foreach (KeyValuePair<string, string> kv in values)
            {
                content = content.Replace(string.Format("{{{0}}}", kv.Key), kv.Value);
            }
            return content;
        }
    }
}
